#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import socket
import struct

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect_ex(("127.0.0.1", 2006))

while True:
    inp = input(">>>: ").strip()
    if not inp: continue
    # 1、发送命令
    client.send(inp.encode("utf-8"))
    # 2、获取报头长度
    header = client.recv(4)
    total_size = struct.unpack("i", header)[0]
    recv_size = 0       # 接收数据大小
    res = b""           # 数据拼接
    while recv_size < total_size:
        data = client.recv(1024)    # 1024-8096之间
        res += data     # 数据的拼接
        recv_size += len(data)  # 每次增加接收的长度
    print(res.decode("gbk"))
